package io.renren.modules.resumes.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.exception.RRException;
import io.renren.common.utils.CommonBusinessStatus;
import io.renren.modules.resumes.dao.ResumeDao;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.resumes.entity.ResumeEntity;
import io.renren.modules.resumes.service.ResumeService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author nyc
 * @email 2691778746@qq.com
 * @date 2022-03-27 01:14:07
 */
@RestController
@RequestMapping("resumes/resume")
public class ResumeController {
    @Autowired
    private ResumeService resumeService;

    @Autowired
    private ResumeDao resumeDao;



    @PostMapping("/resumeApprove/{resumeId}/{isPass}")
    public R resumeApprove(@PathVariable("resumeId") String resumeId,
                           @PathVariable("isPass")String isPass){

        QueryWrapper<ResumeEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("id",resumeId);
        ResumeEntity resumeEntity = resumeDao.selectOne(wrapper);


        if (CommonBusinessStatus.RESUME_NOT_APPROVE.equals(resumeEntity.getResumeApproveStatus())){
            throw new RRException("请先检查简历在做操作");
        }

        resumeEntity.setIsPass(Integer.parseInt(isPass));
        resumeEntity.setResumeApproveStatus(CommonBusinessStatus.RESUME_HAVING_APPROVE);
        resumeDao.updateById(resumeEntity);
        return R.ok();
    }




    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("resumes:resume:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = resumeService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("resumes:resume:info")
    public R info(@PathVariable("id") Long id){
		ResumeEntity resume = resumeService.getById(id);

        return R.ok().put("resume", resume);
    }

    /**
     * 保存
     */
    @Transactional
    @RequestMapping("/save")
    @RequiresPermissions("resumes:resume:save")
    public R save(@RequestBody ResumeEntity resume){
		resumeService.save(resume);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("resumes:resume:update")
    public R update(@RequestBody ResumeEntity resume){
		resumeService.updateById(resume);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("resumes:resume:delete")
    public R delete(@RequestBody Long[] ids){
		resumeService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
